package com.ld.admin.model.system;

import java.io.Serializable;
import java.util.Date;

import javax.validation.constraints.NotEmpty;

import com.ld.shieldsb.annotation.field.DealField.Field;
import com.ld.shieldsb.annotation.field.db.Unique;
import com.ld.shieldsb.annotation.model.ModelAnno.Model;
import com.ld.shieldsb.annotation.model.ModelAnno.TableName;
import com.ld.shieldsb.common.core.util.DateUtil;

import lombok.Data;

/**
 * 
 * 临时账号(sys_user_temp)
 * 
 * @ClassName SysUserTempModel
 * @author <a href="mailto:donggongai@126.com" target="_blank">吕凯</a>
 * @date 2019年09月30日 17:06:01
 *
 */
@Model(name = "临时账号")
@TableName("sys_user_temp")
@Data
public class SysUserTempModel implements Serializable {
    private static final long serialVersionUID = 5342556793327439827L;

    /*主键*/
    private Long id;
    /*父编号，上级编号*/
    @Field(name = "主账号")
    private Long parentId;
    /*临时账号显示名称*/
    @Field(name = "账号名称")
    @NotEmpty(message = "显示名称不能为空！")
    private String accountName;
    /*临时账号*/
    @Field(name = "临时账号")
    private String account;
    /*临时密码*/
    @NotEmpty(message = "不能为空！")
    @Field(name = "临时密码")
    @Unique(compsite = "parentId")
    private String password;
    /*有效期至*/
//    @NotEmpty(message = "有效期至不能为空！")
    private Date dateUntil;
    /*创建人*/
    private Long createBy;
    /*创建人姓名*/
    private String createName;
    /*创建时间*/
    private Date createTime;
    /*修改人*/
    private Long updateBy;
    /*修改人姓名*/
    private String updateName;
    /*修改时间*/
    private Date updateTime;
    /*状态0正常-1删除*/
    private Integer state;
    /*允许访问的ip*/
    private String allowIp;

    // 关联的主账号
//    @OnlyShow
//    @Link(field = "parentId")
//    private SystemUser user;

    public boolean isExpired() {
        if (getDateUntil() == null) {
            return true;
        }
        return DateUtil.timeBetween(new Date(), getDateUntil()) <= 0;
    }
}
